<template>
    <div class="app-container">
        <div class="search-container">
            <el-form :model="queryParams" ref="queryParamsRef" :inline="true" label-width="100px">
                <el-form-item label="患者姓名" prop="name">
                    <el-input v-model="queryParams.name" class="width-120" placeholder="请输入患者姓名" clearable
                        @keyup.enter="handleQuery" />
                </el-form-item>
                <el-form-item label="入/出院状态 ：" prop="inFlag" v-if="props.columnIsShow">
                    <el-select v-model="queryParams.inFlag" placeholder="请选择住院标识" clearable>
                        <el-option v-for="dict in dictDataMap['entry_and_exit_hospital_status']" :key="dict.dictValue"
                            :label="dict.dictLabel" :value="dict.dictValue" />
                    </el-select>
                </el-form-item>
                <el-form-item label="身份证号" prop="idNo">
                    <el-input v-model="queryParams.idNo" placeholder="请输入身份证号" clearable @keyup.enter="handleQuery" />
                </el-form-item>
                <el-form-item label="电话" prop="phone">
                    <el-input v-model="queryParams.phone" placeholder="请输入电话" clearable @keyup.enter="handleQuery" />
                </el-form-item>
                <el-form-item>
                    <query-form-button @handleQuery="handleQuery" @resetQuery="resetQuery" />
                    <span class="ys-css ml10">点击列表患者行，引入登记信息</span>
                </el-form-item>
            </el-form>
        </div>

        <el-table v-adaptive="250" :border="true" :data="hospitalizationNoticeList" :stripe="true" highlight-current-row
            :header-cell-style="$headerCellStyle" @row-click="rowClick">
            <el-table-column label="住院号" :align="'center'" prop="hospitalNo" width="120px" v-if="props.columnIsShow" />
            <el-table-column label="患者姓名" :align="'center'" prop="name" width="80px" />
            <el-table-column label="性别" :align="'center'" prop="sex" width="60px">
                <template #default="scope">
                    <dict-data-tag :options="dictDataMap['sys_user_sex']" :value="scope.row.sex" />
                </template>
            </el-table-column>
            <el-table-column label="年龄" :align="'center'" prop="age" width="160px">
                <template #default="scope">
                    {{ scope.row.age }} 岁
                    {{ scope.row.ageMonth }} 月
                    {{ scope.row.ageDay }} 天
                    {{ scope.row.ageHours }} 时
                    {{ scope.row.ageMinutes }} 分
                </template>
            </el-table-column>
            <el-table-column label="在院标识" :align="'center'" prop="inFlag" width="70px" v-if="props.columnIsShow">
                <template #default="scope">
                    <dict-data-tag :options="dictDataMap['entry_and_exit_hospital_status']" :value="scope.row.inFlag" />
                </template>
            </el-table-column>
            <el-table-column label="身份证号" :align="'center'" prop="idNo" width="140px" />
            <el-table-column label="电话" :align="'center'" prop="phone" width="95px" />
            <el-table-column label="费别" :align="'center'" prop="chargeType" width="100px" v-if="props.columnIsShow">
                <template #default="scope">
                    <dict-data-tag :options="dictDataMap['medical_insurance_type']" :value="scope.row.chargeType" />
                </template>
            </el-table-column>
            <el-table-column label="入院时间" :align="'center'" prop="admissionTime" width="130" v-if="props.columnIsShow">
                <template #default="scope">
                    <span>{{ $parseTime(scope.row.admissionTime, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
                </template>
            </el-table-column>
            <el-table-column label="入院科室" :align="'center'" prop="deptAdmissionToName" width="90px" />
            <el-table-column label="入院病区" :align="'center'" prop="wardAdmissionToName" width="90px" />
            <el-table-column label="开单医生" :align="'center'" prop="createByName" width="90px" />
            <el-table-column label="入院情况" :align="'center'" prop="hospitalSituation" width="90px"
                v-if="props.columnIsShow">
                <template #default="scope">
                    <dict-data-tag :options="dictDataMap['admission_situation_dict']"
                        :value="scope.row.hospitalSituation" />
                </template>
            </el-table-column>
            <el-table-column label="隔离情况" :align="'center'" prop="quarantine" width="90px" v-if="props.columnIsShow">
                <template #default="scope">
                    <dict-data-tag :options="dictDataMap['sys_yes_no']" :value="scope.row.quarantine" />
                </template>
            </el-table-column>
            <el-table-column label="入院诊断" :align="'center'" prop="diagnosis" :show-overflow-tooltip="true"
                v-if="props.columnIsShow" />
            <el-table-column label="门诊诊断" :align="'center'" prop="clinicDiagnosis" :show-overflow-tooltip="true"
                width="150px" />
            <el-table-column label="操作" :align="'center'" v-if="props.columnIsShow"
                class-name="small-padding fixed-width" width="100">
                <template #default="scope">
                    <el-tooltip v-if="props.columnIsShow" class="item" content="修改" effect="dark" placement="top">
                        <el-button circle type="success" @click="handleUpdate(scope.row)">
                            <i-ep-edit />
                        </el-button>
                    </el-tooltip>
                    <el-button type="danger" @click="handleDelete(scope.row)" v-if="props.columnIsShow"
                        v-hasPerm="['business:HospitalizationNotice:remove']">
                        <template #icon>
                            <i-ep-delete />
                        </template>删除
                    </el-button>
                </template>
            </el-table-column>
        </el-table>
        <pagination v-show="total > 0" :total="total" v-model:page="queryParams.pageNum"
            v-model:limit="queryParams.pageSize" @pagination="getList" />
    </div>
</template>
<script lang="ts">
export default {
    name: "HospitalizationNotice"
}
</script>
<script setup lang="ts">
import {
    addHospitalizationNotice, delHospitalizationNotice, getHospitalizationNotice,
    listHospitalizationNotice, updateHospitalizationNotice, selectPageHospitalizationNotice
} from "@/api/hospitalization/HospitalizationNotice.ts";

import { useDictStoreHook } from "@/store/modules/dict";
import { useUserStoreHook } from "@/store/modules/user";
const useUserStore = useUserStoreHook();
// 登录用户信息
const userInfo = <UserInfoBusi>useUserStore.user.userInfo;
const dictStore = useDictStoreHook();
let dictDataMap = ref(dictStore.isTypeGetData('profession_dict', 'nationality_dict', 'medical_insurance_type', 'sys_yes_no',
    'sys_user_sex', 'nation_dict', 'marriage_dict', 'admission_situation_dict', 'entry_and_exit_hospital_status'))

const { proxy } = getCurrentInstance() as any;

const emits = defineEmits(['rowClick'])
const formRef = ref();
const queryParamsRef = ref()
const hospitalizationNoticeList = ref<any>([]);
const open = ref(false);
const total = ref(0);

const props = defineProps({
    columnIsShow: {
        type: Boolean,
        default: true
    }
})

const queryParams = ref({
    pageNum: 1,
    pageSize: 10,
    clinicId: "",
    name: "",
    inputCode: "",
    sex: "",
    age: "",
    nation: "",
    nationality: "",
    marriage: "",
    occupation: "",
    bedNum: "",
    birthdayDate: "",
    nativePlace: "",
    nativePlaceCode: "",
    zipCode: "",
    homeplace: "",
    homeplaceCode: "",
    address: "",
    addressCode: "",
    identity: "",
    inFlag: "",
    idNo: "",
    phone: "",
    contacts: "",
    contactsRelation: "",
    contactsNation: "",
    contactsIdentity: "",
    contactsAddressCode: "",
    contactsAddress: "",
    contactsPhone: "",
    unitInContract: "",
    chargeType: "",
    deptAdmissionTo: "",
    wardAdmissionTo: "",
    admissionTime: "",
    acceptingMoney: "",
    attackdate: "",
    hospitalSituation: "",
    quarantine: "",
    diagnosis: "",
    diagnosisDesc: "",
    attention: "",
    orgId: userInfo.orgId,
})

/** 查询住院通知单列表 */
function getList() {
    queryParams.value.inFlag = "4"
    selectPageHospitalizationNotice(queryParams.value).then((response: any) => {
        hospitalizationNoticeList.value = response.rows;
        total.value = response.total;
    });
}

// 取消按钮
function cancel() {
    open.value = false;
}

/** 搜索按钮操作 */
function handleQuery() {
    queryParams.value.pageNum = 1;
    getList();
}

/** 重置按钮操作 */
function resetQuery() {
    queryParamsRef.value.resetFields()
    // proxy.resetForm("queryRef");
    handleQuery();
}


function rowClick(row) {
    emits("rowClick", row)
}

defineExpose({
    getList
})
getList();
</script>

<style scoped>
:deep(.el-drawer__header) {
    margin-bottom: 0 !important;
}
</style>
